package com.leijingqi.controller;

import com.leijingqi.pojo.Dept;
import com.leijingqi.pojo.Result;
import com.leijingqi.service.DeptService;
import com.leijingqi.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理Controller
 */
@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    /**
     * 查询接口
     */
//    @RequestMapping(value = "/depts",method = RequestMethod.GET)
    @GetMapping
    public Result list (){
        log.info("ALL部门全部数据");
        //调用service 查询部门数据
       List<Dept> deptList = deptService.list();
        return  Result.success(deptList);
    }
    /**
     * 删除接口
     */
    @DeleteMapping("/{id}")
    public Result delete (@PathVariable Integer id) throws Exception {
        log.info("删除"+id);
         deptService.delete(id);

         return  Result.success();
    }

    /*
     * 新增部门
     */
    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("新增部门：{}",dept);
        deptService.add(dept);
        return  Result.success();
    }
    /*
     * 查询部门
     */
    @GetMapping("/{id}")
    public Result getData(@PathVariable Integer id){
        Dept dep =  deptService.getData(id);
        return Result.success(dep);
    }
    /*
    修改部门
     */
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改部门：{}",dept);
        deptService.update(dept);
        return Result.success();
    }
}
